<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" import="com.model.AssetsBean"%>
	<%@ page import="java.lang.reflect.*" %>
	<%@ page import="com.common.uilt.TableTitle" %>
	<%@ page import="javax.persistence.Table" %>
	<%@ page import="java.util.List" %>
	<%@ page import="java.util.Map" %>
	<%@ page import="java.util.Arrays" %>
	<%@ page import="java.math.BigDecimal" %>
	<%@ page import="java.text.DecimalFormat" %>
	<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="../../common/base.jsp"%>
<%
	response.setCharacterEncoding("utf-8");
%>
<%!
	public String getMethodName(String fildeName){
		byte[] items = fildeName.getBytes();
		items[0] = (byte) ((char) items[0] - 'a' + 'A');
	return new String(items);
	}
%>
<!DOCTYPE html>
<html lang="zh-cn">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="${path }/dist/css/bootstrap.css" rel="stylesheet">
<link href="${path }/dist/css/bootstrap-overrides.css" rel="stylesheet">
<title>编辑资产</title>
<!-- Button -->
<link href="${path }/dist/css/compiled/elements.css" rel="stylesheet">
<!-- libraries -->
<link rel="stylesheet" type="text/css"  href="${path }/dist/css/font-awesome.css">
<!-- this -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/app.css">
<!-- 右键菜单插件 -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/smartMenu.css">

<link href='${path }/dist/css/zTreeStyle/zTreeStyle.css' rel='stylesheet' />
<link href="${path }/dist/css/bootstrap-datetimepicker.min.css" rel="stylesheet"><%--时间日期工具 --%>
<link rel="stylesheet" type="text/css" href="${path }/back/ifrom.css">
<script src="${path }/dist/js/jquery.min.js"></script>
<script src="${path }/dist/js/theme.js"></script>
<script src='${path }/dist/js/bootstrap.min.js'></script>
<script src="${path }/dist/js/cookie.js"></script>
<script src='${path }/dist/js/jquery-smartMenu.js'></script>
<script src='${path }/dist/js/jquery.ztree.core-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.excheck-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.exedit-3.5.js'></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.min.js"></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<style>
.left_tree{
	height: 430px;
	overflow: auto;
	border: 1px solid #ccc;
	 border-radius: 5px;
}
#pad-wrapper h3{
	font-family: "黑体";
}
#content_table th{
	padding: 5px 3px;
	vertical-align:middle;
	word-break: keep-all;/*强制不换行*/
	cursor: pointer;
} 
#content_table td{
	padding: 10px 5px;
	vertical-align:middle;
	word-break: keep-all;/*强制不换行*/
} 
.my_modal{
	position: absolute;
	height: 200px;
	width: 600px;
	display:none;
	left: 20%;
	top: 10%;
}
.my_input {
  width: 100px;
  height: 28px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.228571429;
  color: #555555;
  vertical-align: middle;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border-radius: 2px;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
.my_input:focus {
  border-color: #66afe9;
  outline: 0;
  -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
#table_setting{
	left: 30%;
	top: 10%;
	width: 300px;
}
#table_setting table tr th,#table_setting table tr td{
	height: 10px;
	padding-top: 0px;
	padding-bottom: 0px;
}
#table_setting_form input[type=text]{
	width: 50px;
}
select{
	width: 100%;
}
input[readonly]{
	background-color: #fff !important;
	cursor: text !important;
}
.menuContent {padding-top: 10px;border: 1px solid #617775;background: #f0f6e4;width:160px;height:260px;overflow-y:scroll;overflow-x:auto;}
</style>
</head>
<bady onbeforeunload="return '当前页面还有未保存的数据，确定不保存就离开了吗？';">
<div id="pad-wrapper">
	<div class="row head">
	<div class="col-md-12">
			<h3>浏览录入<em><small>右键对资产列表进行操作</small></em></h3>
			</div>
	</div>
	<hr>
<!-- ${path }/back/assetsMS!browseentry -->
	<form action="${path }/back/assetsPD!browseentry" id="list_page_form" method="post">
	<div class="col-md-12 table-wrapper users-table">
		<div class="row filter-block">
			<div class="pull-right">
				<input type="text" class="search" name="select_number" value="${select_number}" placeholder="输入要查找的编号：">
				<a class="btn-flat success new-product" id="search" ><i class="icon-search"></i> <span>查找</span></a>
				<a class="btn-flat success new-product" id="btn_adv_Search" ><i class="icon-search"></i> <span>高级查找</span></a>
				<a class="btn-flat success new-product" id="btn_table_setting"><i class="icon-wrench"></i><span>表格设置</span></a>
				<a class="btn-flat success new-product"><i class="icon-repeat"></i> <span>刷新</span></a>
				<%--disabled --%>
			</div><!-- 按钮组 -->
		</div>
		<div class="row" style="margin-top: 5px;">
			<div class="col-md-12" style="overflow-x: auto;">
				<div style="width: 2000px; height: 450px;">
				<table class="table-hover table-bordered" id="content_table">
					<thead><%-- <tr><td><%=request.getAttribute("tableSetting") %></td></tr> --%>
						<%
						AssetsBean ab= new AssetsBean();
				 		String str =(String)request.getAttribute("tableSetting");
				 		String[] arraystr=str.split(",");
				 		Field[] field=null;
					try {
				 		
						field= ab.getClass().getDeclaredFields();
						
						for (Field field2 : field) {
							String name = field2.getName();
							if(field2.getAnnotation(TableTitle.class)!=null){
								if(str.contains(name)){
								%>
								<th class="sortable"><span data-property='<%=name %>'><%=((TableTitle)field2.getAnnotation(TableTitle.class)).title() %></span></th>
							<%}} 
						}
					
					}catch (Exception e) {
	 					e.printStackTrace();
	 				}
				 		%>	
					</thead>
					<tbody id="node_tbody">
						<%
							List<Map<String,Object>> l=(List<Map<String,Object>>)request.getAttribute("assetsList");
							if(l.size()==0){%>
								<tr>
									<td colspan="21">没有结果集</td>
								</tr>
							<%}else{
								 DecimalFormat df = new DecimalFormat("###,##0.00");
								 //df.setRoundingMode(RoundingMode.FLOOR);
							for(Map<String,Object> m:l){%>
								<tr data-id='<%=m.get("id")%>'>
								<%for(String s:arraystr) {
									String value=m.get(s)==null||"".equals(m.get(s).toString())?"无":m.get(s).toString();
											//System.out.println((i++)+":"+( ));
											 if(m.get(s) instanceof BigDecimal){
												value=df.format(m.get(s));
											} 
									%>
									<td><%=value %></td>
									<%
										
									} %>
								</tr>
							<%}}
						%>
					</tbody>
					
				</table>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<%@include file="../page.jsp" %>
			</div>
		</div>
		<div class="row filter-block" style="margin-top: 10px; ">
			<div class="pull-left">
				<a class="btn-flat success new-product" href="javascript:void(0);" id="add_edit"><i class="icon-plus"></i> <span>新增</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="out_depot" data-modal><i class="icon-truck"></i><span>出库</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="ref_out_depot" data-modal><i class="icon-truck"></i><span>修改本月出库单据</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="refunding" data-modal><i class="icon-signin"></i><span>退库</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="allocation" data-modal><i class="icon-sitemap"></i><span>调拨</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="loan" data-modal><i class="icon-random"></i><span>借出</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="return_assets" data-modal><i class="icon-star"></i><span>归还</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="carry" data-modal><i class="icon-star-half"></i><span>送修</span></a>
				<a class="btn-flat success new-product" href="javascript:void(0);" id="scrapped" data-modal><i class="icon-remove"></i><span>报废</span></a>
				<a class="btn-flat success new-product"><i class="icon-download-alt"></i><span>导出xls</span></a>
				<%--disabled --%>
			</div><!-- 按钮组 -->
		</div>
	</div>
	
	<div class="my_modal" id="adv_Search_modal" style="width: 800px;left: 10%;">
	    <div class="modal-content ">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="hideMenu('#adv_Search_modal')"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">高级搜索</h4>
	      </div>
	      <div class="modal-body">
	       		<table class="table table-bordered  table-condensed">
					<tbody>
						<tr>
							<td class="title"> 编号：</td>
							<td>
							<input type="text" class="form-control input-sm" name="select_number" value="${select_number }"/>
							</td>
							<td class="title">资产类别：</td>
							<td><input type="text" class="form-control input-sm" name="search_class_name" value="${search_class_name }"/></td>
							<td class="title">资产名称</td>
							<td><input type="text" class="form-control input-sm" name="search_name" value="${search_name }"/></td>
							
						</tr>
						<tr>
							<td class="title">规格型号：</td>
							<td><input type="text" class="form-control input-sm" name="search_specification" value="${search_specification }"/></td>
							<td class="title">计量单位：</td>
							<td><input type="text" class="form-control input-sm" name="search_measure" list="measure_list" value="${search_measure }"/>
								<datalist id="measure_list">
								<c:forEach var="wal" items="${assetsMeasureList }">
									<option value="${wal.measure_name }" label="${wal.measure_name }">
									</c:forEach>
								</datalist>
							</td>
							<td class="title">资产来源</td>
							<td><input type="text" class="form-control input-sm" name="search_source" list="source_list" value="${search_source }"/>
								<datalist id="source_list">
								<c:forEach var="wal" items="${assetsSourceList }">
									<option value="${wal.measure_name }" label="${wal.measure_name }">
									</c:forEach>
								</datalist>
							</td>
						</tr>
						<tr>
							<td class="title">购置日期：</td>
							<td colspan="2"><input type="text" class="my_input input-sm form_datetime" name="search_buy_date_go" readonly="readonly"  value="${search_buy_date_go }"/>
								<span>至</span>
								<input type="text" class="my_input input-sm form_datetime" name="search_buy_date_end" readonly="readonly" value=""/>
							</td>
							<td class="title">登记日期：</td>
							<td colspan="2"><input type="text" class="my_input input-sm form_datetime" name="search_register_data_go" readonly="readonly"  value="${search_register_data_go }"/>
								<span>至</span>
								<input type="text" class="my_input input-sm form_datetime" name="search_register_data_end" readonly="readonly" value="<fmt:formatDate value="${date}" pattern="yyyy-MM-dd"/>"/>
							</td>
						</tr>
						<tr>
							<td class="title">资产单价：</td>
							<td colspan="2"><input type="text" class="my_input input-sm" name="search_unit_price_go" placeholder="0.00￥"  value="${ search_unit_price_go}"/>
							<span>至</span>
							<input type="text" class="my_input input-sm" name="search_unit_price_end" placeholder="0.00￥"  value="${search_unit_price_end }"/></td>
							<td class="title">使用年限：</td>
							<td colspan="2">
								   <input type="text" class="my_input input-sm" placeholder="年" name="search_years_go"  value="${search_years_go }">
								   <span>至</span>
								   <input type="text" class="my_input input-sm" placeholder="年" name="search_years_end"  value="${search_years_end }">
							</td>
						</tr>
						<tr>
							<td class="title">资产状态：</td>
							<td>
								<input type="text" class="form-control input-sm" name="search_status" list="status_list" value="${search_status }"/>
								<datalist id="status_list">
								<c:forEach var="wal" items="${assetsStatusList }">
									<option value="${wal.measure_name }" label="${wal.measure_name }">
									</c:forEach>
								</datalist>
							</td>
							<td class="title">财务编码：</td>
							<td><input type="text" class="form-control input-sm" name="search_f_number"  value="${search_f_number }"/></td>
							<td class="title">机器序号：</td>
							<td><input type="text" class="form-control input-sm" name="search_machine_no"  value="${search_machine_no }"/></td>
						</tr>
					</tbody>
				</table>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" onclick="hideMenu('#adv_Search_modal')">Close</button>
	        <button type="button" class="btn btn-primary" id="adv_Search_form_submit">确认提交</button>
	      </div>
	    </div>

</div>
	</form>

</div>
<div class="my_modal" id="table_setting">
	<form action="#" method="post" id="table_setting_form">
	    <div class="modal-content ">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="hideMenu('#table_setting')"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">表格设置</h4>
	      </div>
	      <div class="modal-body">
	       		<table class="table table-bordered  table-condensed">
					<thead>
						<tr><th colspan="3">设置表格显示的字段是否显示。</th></tr>
						<tr>
							<th>字段名称</th>
							<th><span> <input type="checkbox" name="field_setting"/></span>是否显示</th>
							<th>宽度</th>
						</tr>
					</thead>
					<tbody>
						<%
						try {
					 		if(ab.getClass().isAnnotationPresent(Table.class)){
								out.print("<input type='hidden' name='setting_key' value='"+((Table)ab.getClass().getAnnotation(Table.class)).name()+"'/>");
							}
							for (Field field2 : field) {
								String name = field2.getName();
								
								if(field2.isAnnotationPresent(TableTitle.class)){
									%>
									<tr data-name='<%=name %>'>
										<td><%=((TableTitle)field2.getAnnotation(TableTitle.class)).title() %>
										</td>
										<td>
											<input type="checkbox" name="field_setting" <%if(str.contains(name)){ %>checked="checked" <%} %> />
										</td>
										<td><input type="text" name='width' value="150"/></td>
									</tr>
								<%} 	
							}
						}catch (Exception e) {
		 					e.printStackTrace();
		 				}
					 		%>
					</tbody>
				</table>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" onclick="hideMenu('#table_setting')">Close</button>
	        <button type="button" class="btn btn-primary" id="table_setting_form_submit">确认提交</button>
	      </div>
	    </div>
	  </form>
</div>
<div class="my_modal" id="edit_assets_modal" style="width: 800px;left: 10%;">
	<form action="" id="edit_assets_form">
	    <div class="modal-content ">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="hideMenu('#edit_assets_modal')"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">编辑资产</h4>
	      </div>
	      <div class="modal-body">
	       		<table class="table table-bordered  table-condensed">
					<tbody>
						<tr>
							<td class="title"> 编号：</td>
							<td>
							<input type="text" class="form-control input-sm" name="ab.a_number" value="" readonly="readonly"/>
							</td>
							<td class="title">资产类别：</td>
							<td><input type="text" class="form-control input-sm" name="ab.a_class_name" value="" readonly="readonly"/></td>
							<td class="title">资产名称</td>
							<td><input type="text" class="form-control input-sm" name="ab.a_name" value=""/></td>
							
						</tr>
						<tr>
							<td class="title">规格型号：</td>
							<td><input type="text" class="form-control input-sm" name="ab.a_specification" value=""/></td>
							<td class="title">计量单位：</td>
							<td><select name="ab.a_measure">
									<c:forEach var="wal" items="${assetsMeasureList }">
				    				<option value="${wal.measure_name }">${wal.measure_name }</option>
									</c:forEach>
								</select>
							</td>
							<td rowspan="2" class="title">
								备注
							</td>
							<td rowspan="2"><textarea wrap="virtual" class="form-control" name='ab.a_remark' ></textarea></td>
						</tr>
						<tr>
							<td class="title">财务编码：</td>
							<td><input type="text" class="form-control input-sm" name="ab.a_f_number"  value=""/></td>
							<td class="title">机器序号：</td>
							<td><input type="text" class="form-control input-sm" name="ab.a_machine_no"  value=""/></td>
						</tr>
					</tbody>
				</table>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" onclick="hideMenu('#edit_assets_modal')">Close</button>
	        <button type="button" class="btn btn-primary" id="edit_assets_form_submit">确认提交</button>
	      </div>
	    </div>
	    <input type="hidden" name="ab.id">
	</form>
</div>
<div id="a_class_nameMenu" class="menuContent" style="display:none; position: absolute;">
	<ul id="assetstree" class="ztree menutree"></ul>
</div>
	<script type="text/javascript">
	var setting = {
			view: {
				selectedMulti: false,//多选
				showLine: true,
				nameIsHTML: true
			}, callback : {
				beforeClick : assetsclasstree,
			},data:{
				simpleData:{
					enable: true,
				}
			}
		};
	var assetsData=[
	                [{text: "修改", func:editassets },
	                 {text: "删除", func:removeassets }
	                ]
	               ];
	//资产分类树点击事件
	function assetsclasstree(treeId, treeNode){
			$("input[name='search_class_name']").val(treeNode.name);
		return true;
	}
	function editassets(){
		$(this).find("td").each(function(i){
			var name=$(this).closest("table").find("th>span").eq(i).data("property");
			var input_obj=$("#edit_assets_modal [name='ab."+name+"']");
			if(input_obj.length>0){
				input_obj.val($(this).html());
			}
		});
		$("#edit_assets_modal [name='ab.id']").val($(this).data("id"));
		$("#edit_assets_modal").slideDown("fast");
	}
	function removeassets(){
		if(confirm("确认删除？")){
			var data = new Array();
			data.push({name:"id",value:$(this).data("id")});
			var saveURL = "${path}/back/assetsMS!delassets?date="+new Date()+"";
			jQuery.post(saveURL,data,function(jsonData){
				if(jsonData.info){
					alert(jsonData.text);
				 	window.location.reload();
				}else{
					alert("删除失败：原因\n"+jsonData.text);
				}
			},"json");
		}
	}
	$(document).ready(function() {
		var saveURL = "${path}/back/tree!assetsclasstree?date="+new Date()+"";
		jQuery.post(saveURL,null,function(jsonData){
			$.fn.zTree.init($("#assetstree"),setting,jsonData);
		},"json");
		
		
		$("#node_tbody tr").smartMenu(assetsData,{name:"assetstrmenu"});
		//展开资产分类树
		$("input[name='search_class_name']").bind("focus",{id:"#a_class_nameMenu"},function(e){
			var cityObj = $(this);
			var cityOffset = cityObj.offset();
			$(e.data.id+"").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown",{id:e.data.id}, onBodyDown);
		});
		$("#add_edit").click(function(){
			//window.open("${path }/back/assetsMS!newOreditAssets","editmodal",
				//	"'height=500,width=1134,top=10,left=100,scrollbars=yes,toolbar=no,menubar=no, resizable=no, status=no");
			var ruturnmsg=window.showModalDialog("${path }/back/assetsMS!newOreditAssets",null,"dialogWidth=1134px;dialogHeight=500px;center:yes");
			if(ruturnmsg!=null) alert(ruturnmsg);
		
		});
		$("[data-modal]").each(function(){
			$(this).click(function(){
				var moadlURL = $(this).attr('id');
				var ruturnmsg=window.showModalDialog("${path }/back/assetsMS!"+moadlURL,null,"dialogWidth=1130px;dialogHeight=800px;center:yes");
				if(ruturnmsg!=null) alert(ruturnmsg);
			});
		});
		$("#btn_table_setting").bind("click",{id:"#table_setting"},function(e){
			$(e.data.id+"").slideDown("fast");
			$("body").bind("mousedown",{id:e.data.id}, onBodyDown);
		});
		$("#search").click(function(){
			$(this).closest("form").submit();
		});
		$("#btn_adv_Search").bind("click",{id:"#adv_Search_modal"},function(e){
			$(e.data.id+"").slideDown("fast");
		});
		$("#adv_Search_form_submit").click(function(){
			$(this).closest("form").submit();
		});
		$("#table_setting_form_submit").click(function(){
			var checkbox_obj=$(".table tr>td input:checkbox:checked");
			var valuearray=new Array();
			checkbox_obj.each(function(){
				var tr_obj=$(this).parent().parent();
				valuearray.push(tr_obj.data('name'));//+"="+tr_obj.find("input[name='width']").val());
				//最好做成json 格式
			});
			var data=[];
			data.push({name:"setting_value",value:valuearray.join(',')});
			data.push({name:"setting_key",value:$("input[name='setting_key']").val()});
			var saveURL = "${path}/back/system!settingtable?date="+new Date()+"";
			jQuery.post(saveURL,data,function(jsonData){
				if(jsonData.info){
					alert(jsonData.text);
				 	window.location.reload();
				}else{
					alert("修改失败：原因\n"+jsonData.text);
				}
			},"json");
			
		});
		$("#edit_assets_form_submit").click(function(){
			var data=$("#edit_assets_form").serializeArray();
			var saveURL = "${path}/back/assetsMS!editassets?date="+new Date()+"";
			jQuery.post(saveURL,data,function(jsonData){
				if(jsonData.info){
					alert(jsonData.text);
				 	window.location.reload();
				}else{
					alert("修改失败：原因\n"+jsonData.text);
				}
			},"json");
		});
	});
	//时间日期
	$(".form_datetime").datetimepicker({format: 'yyyy-mm-dd',language:  'zh-CN',weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1,
        minView: 2,
        pickerPosition:"bottom-left"});
	function fromisnotnull(fromdom){
		var  pass =true;
		$("input[type='text'][data-vail]",fromdom).each(function(){
			if($(this).val()==null||$(this).val()==""){
				alert("*为必填项");
				pass =false;
				return false;
			}
		});
		return pass;
	}
	function onBodyDown(evetnt){
		if(!($(evetnt.target).closest(evetnt.data.id).length>0)){
			hideMenu(evetnt.data.id);
		}
	}
	//解除 body绑定
	function hideMenu(id){
		$(id+"").fadeOut("fast");
		$("body").unbind("mousedown",onBodyDown);
	}
	</script>
</bady>
</html>